import 'dart:ui';

import 'package:common_utils/common_utils.dart';
import 'package:get/get.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/net/dio_api.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';

import '../model/models.dart';

class MarketConteroller extends GetxController {
  static final String MarketScreeningID = 'MarketScreeningID';
  static final String MarketStartingID = 'MarketStartingID';
  static final String MarketResaleID = 'MarketResaleID';

  static final String MarketCategoryID = 'MarketCategoryID';
  static final String MarketTypeID = 'MarketTypeID';
  static final String MarketSpecialID = 'MarketSpecialID';

  //当前下标
  int currentIndex = 0;

  //时间和价格排序
  int orderType = 0;
  int turnOrderType = 0;

  //首发
  int startingTimeType = 0;
  int startingPriceType = 0;
  //转售
  int resaleTimeType = 0;
  int resalePriceType = 0;

  //筛选 首发 转售
  int _selectCategoryNum = 0;
  int _selectTypeNum = 0;
  int _selectSpecialNum = 0;

  int _selectSellCategoryNum = 0;
  int _selectSellTypeNum = 0;
  int _selectSellSpecialNum = 0;

  //回掉
  VoidCallback? onPressed;

  late GoodsInfo _goodsinfo;
  ///状态
  late int status = LoadStatusType.loading;

  GoodsInfo get goodsinfo => _goodsinfo;

  //是否存在
  bool get hasGoodsinfo => ObjectUtil.isNotEmpty(_goodsinfo);

  List<SpecialTypeModel> typeList = [SpecialTypeModel.fromJson({"title":"全部","id":0})];

  static MarketConteroller get to => Get.find<MarketConteroller>();


  int get selectCategoryNum => _selectCategoryNum;

  set selectCategoryNum(int value) {
    _selectCategoryNum = value;
    onPressed!();

    update([MarketScreeningID]);
  }

  int get selectTypeNum => _selectTypeNum;

  set selectTypeNum(int value) {
    _selectTypeNum = value;
    onPressed!();
    update([MarketScreeningID]);
  }

  int get selectSpecialNum => _selectSpecialNum;

  set selectSpecialNum(int value) {
    _selectSpecialNum = value;
    onPressed!();
    update([MarketScreeningID]);
  }

  int get selectSellCategoryNum => _selectSellCategoryNum;

  set selectSellCategoryNum(int value) {
    _selectSellCategoryNum = value;
    onPressed!();
    update([MarketScreeningID]);
  }

  int get selectSellTypeNum => _selectSellTypeNum;

  set selectSellTypeNum(int value) {
    _selectSellTypeNum = value;
    onPressed!();
    update([MarketScreeningID]);
  }

  int get selectSellSpecialNum => _selectSellSpecialNum;

  set selectSellSpecialNum(int value) {
    _selectSellSpecialNum = value;
    onPressed!();
    update([MarketScreeningID]);
  } //转售筛选


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getScreeningData();
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }

  //排序时间
  changeSortingTime(int index){
    if(index == 0){
      startingPriceType = 0;
      if(startingTimeType == 0){
        startingTimeType = 1;
        orderType = 3;
      }else if(startingTimeType == 1){
        startingTimeType = 2;
        orderType = 4;
      }else{
        startingTimeType = 0;
        orderType = 0;
      }
      update([MarketStartingID]);
    }else{
      resalePriceType = 0;
      if(resaleTimeType == 0){
        resaleTimeType = 1;
        turnOrderType = 3;
      }else if(resaleTimeType == 1){
        resaleTimeType = 2;
        turnOrderType = 4;
      }else{
        resaleTimeType = 0;
        turnOrderType = 0;
      }
      update([MarketResaleID]);
    }
  }

  //排序价格
  changeSortingPrice(int index){
    if(index == 0){
      startingTimeType = 0;
      if(startingPriceType == 0){
        startingPriceType = 1;
      }else if(startingPriceType == 1){
        startingPriceType = 2;
      }else{
        startingPriceType = 0;
      }
      orderType = startingPriceType;
      update([MarketStartingID]);
    }else{
      resaleTimeType = 0;
      if(resalePriceType == 0){
        resalePriceType = 1;
      }else if(resalePriceType == 1){
        resalePriceType = 2;
      }else{
        resalePriceType = 0;
      }
      turnOrderType = resalePriceType;
      update([MarketResaleID]);
    }
  }


  //获取数据
  void getDataList() async {
    // try {
    //   _goodsinfo = await ServiceRepository.goodsInfo(id:id);
    //   status = LoadStatusType.success;
    // } catch (e, s) {
    //   status = LoadStatusType.empty;
    //   http.setError(e, s);
    // }

  }

  Future<void> getScreeningData() async {
    try{
     List list = await ServiceRepository.goodsSpecialTypeList();
     list.forEach((element) {
       typeList.add(element);
     });
    }catch(e,s){

    }
    update([MarketScreeningID]);
  }

}
